#!/usr/bin/env python
    ##########################################################################
    ##(c) 2008 Bastian Damman                                               ##
    ##                                                                      ##
    ##This file is part of Kaboom-O-rama.                                   ##
    ##                                                                      ##
    ##Kaboom-O-rama is free software: you can redistribute it and/or modify ##
    ##it under the terms of the GNU General Public License as published by  ##
    ##the Free Software Foundation, either version 3 of the License, or     ##
    ##(at your option) any later version.                                   ##
    ##                                                                      ##
    ##Kaboom-O-rama is distributed in the hope that it will be useful,      ##
    ##but WITHOUT ANY WARRANTY; without even the implied warranty of        ##
    ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         ##
    ##GNU General Public License for more details.                          ##
    ##                                                                      ##
    ##You should have received a copy of the GNU General Public License     ##
    ##along with Kaboom-O-rama.  If not, see <http://www.gnu.org/licenses/>.##
    ##########################################################################

class Object:
    img = None              #path -  if player or ai img = folder
    img_animat = False      #bool
    img_speed = 0           #bool
    img_strip = False       #bool
    img_index = 0           #-1 = random, -2 = autofind index, >=0 index (int)
    bbox = None             #tuple(offx, offy, w, h)
    
    solid = False           #bool
    physics = False         #bool
    
    pickup = False          #bool
    pickup_add_health = 0   #int
    pickup_add_points = 0   #int
    pickup_add_ammo = (0, 0)#tuple(weapon, ammo)
    pickup_add_weapon=(0, 0)#tuple(weapon, ammo)
    
    destroyable = False     #bool
    part_hit = None         #index find in ...-class
    part_death = None       #index "    "   "
    
    health = 100            #int
    dammage = 0             #int
    
    friction = 1            #float
    bounce = 0              #float
    
    ai = False              #bool
    ai_walk_speed = (1, 2)  #tuple(min, max)
    ai_gun = None           #index find in  ...-class
    ai_shoot_dist = 128     #int
    player = False          #bool
    
    def __init__(self, index):
        self.index = index
        self.instances = []
    
    def add_instance(self, x, y):
        self.instances.append(Instance(self, x, y))
    
    def save_instances(self, f):
        f.write("       object"+str(self.index)+" = Object"+str(self.index)+"(level)\n")
        instances_pos = []
        for i in self.instances:
            instances_pos.append((i.x, i.y))
        f.write("       obj"+str(self.index)+"_inst = "+str(instances_pos)+"\n")
        f.write("       for i in obj"+str(self.index)+"_inst:\n")
        f.write("           object"+str(self.index)+".add_instance(i)\n")
    
    def save_objects(self, f):
        f.write("class Object"+str(self.index) + ":\n")
        f.write("    img = None\n")
        f.write("    img_animat = False\n")
        f.write("    img_speed = 0\n")
        f.write("    img_strip = False\n")
        f.write("    img_index = 0\n")
        f.write("    bbox = None\n")
        f.write("    \n")
        f.write("    solid = False\n")
        f.write("    physics = False\n")
        f.write("    \n")
        f.write("    pickup = False\n")
        f.write("    pickup_add_health = 0\n")
        f.write("    pickup_add_points = 0\n")
        f.write("    pickup_add_ammo = (0, 0)\n")
        f.write("    pickup_add_weapon = (0, 0)\n")
        f.write("    \n")
        f.write("    destroyable = False\n")
        f.write("    part_hit = None\n")
        f.write("    part_death = None\n")
        f.write("    \n")
        f.write("    health = 100\n")
        f.write("    dammage = 0\n")
        f.write("    \n")
        f.write("    friction = 1\n")
        f.write("    bounce = 0\n")
        f.write("    \n")
        f.write("    ai = False\n")
        f.write("    ai_walk_speed = (1, 2)\n")
        f.write("    ai_gun = None\n")
        f.write("    ai_shoot_dist = 128\n")
        f.write("    player = False\n")
        f.write("\n")
        f.write("    def __init__(self, level):\n")
        f.write("       self.level = level\n\n")
        f.flush()

class Instance:
    def __init__(self, object, x, y):
        self.object = object
        self.x = x
        self.y = y